
         
         /**上传视频功能*/
         $("#file-btn").click(function () {
        	    var $this = $(this);
        	   // $("#cover-vedio-file").click();
        	    
        	    window.open('/child/vedioPreview');
          });
         $("input[name=file]").uploadPreview({ imgContainer: ".preview", width: 190, height: 200, suffix: ["doc"] });
         
 	    function initFileInput(ctrlName) {
 	        var control = $('#' + ctrlName);
 	        control.fileinput({
 	            language: 'zh', //设置语言
 	            uploadUrl: "", //上传的地址
 	            allowedFileExtensions: ['jpg', 'gif', 'png','doc','docx','pdf','ppt','pptx','txt'],//接收的文件后缀
 	            maxFilesNum : 5,//上传最大的文件数量
 	            //uploadExtraData:{"id": 1, "fileName":'123.mp3'},
 	            uploadAsync: true, //默认异步上传
 	            showUpload: true, //是否显示上传按钮
 	            showRemove : true, //显示移除按钮
 	            showPreview : true, //是否显示预览
 	            showCaption: false,//是否显示标题
 	            browseClass: "btn btn-primary", //按钮样式
 	            //dropZoneEnabled: true,//是否显示拖拽区域
 	            //minImageWidth: 50, //图片的最小宽度
 	            //minImageHeight: 50,//图片的最小高度
 	            //maxImageWidth: 1000,//图片的最大宽度
 	            //maxImageHeight: 1000,//图片的最大高度
 	            maxFileSize: 0,//单位为kb，如果为0表示不限制文件大小
 	            //minFileCount: 0,
 	            //maxFileCount: 10, //表示允许同时上传的最大文件个数
 	            enctype: 'multipart/form-data',
 	            validateInitialCount:true,
 	            previewFileIcon: "<i class='glyphicon glyphicon-king'></i>",
 	            msgFilesTooMany: "选择上传的文件数量({n}) 超过允许的最大数值{m}！",
  
 	        }).on('filepreupload', function(event, data, previewId, index) {     //上传中
 	            var form = data.form, files = data.files, extra = data.extra,
 	            response = data.response, reader = data.reader;
 	            console.log('文件正在上传');
 	        }).on("fileuploaded", function (event, data, previewId, index) {    //一个文件上传成功
 	            console.log('文件上传成功！'+data.id);
  
 	        }).on('fileerror', function(event, data, msg) {  //一个文件上传失败
 	            console.log('文件上传失败！'+data.id);
 	        })
 			}
         
        $(function () {
        	
            initFileInput("input-id");
        	
       	   $('#myDatepicker').datetimepicker({
       			 language:  'zh-CN',  
       			 minView: "month",//设置只显示到月份
       		     format: 'yyyy-mm-dd',
                 ignoreReadonly: true,
                 allowInputToggle: true,
                 autoclose:true,//选中关闭
                 pickerPosition: "bottom-left"
             });
        	  
            var options = {
                url: "/child/list",
                getInfoUrl: "/child/get/{id}",
                updateUrl: "/child/edit",
                removeUrl: "/child/remove",
                createUrl: "/child/add",
                saveRolesUrl: "/child/saveUserRoles",
                columns: [
                    {
                        checkbox: true
                    }, {
                        field: 'id',
                        title: '编号',
                        visible :false,
                        editable: false,
                    }, {
                        field: 'childId',
                        title: '孩子编号',
                        visible :false,
                        editable: false,
                    }, {
                        field: 'childName',
                        title: '孩子姓名',
                        editable: false,
                    }, {
                        field: 'nickName',
                        title: '昵称',
                        visible :false,
                        editable: false,
                    }, {
                        field: 'sex',
                        title: '性别',
                        editable: false,
                        formatter: function (code) {
                        	if(code == '0')return '男';
                        	if(code == '1')return '女';
                        	if(code == '2')return '秘密';
                        	return code;
                        }
                    }, {
                        field: 'birthday',
                        title: '出生日期',
                        editable: false,
                        formatter: function (code) {
                            return new Date(code).format("yyyy-MM-dd")
                        }
                    }, {
                        field: 'email',
                        title: '邮箱',
                        visible :false,
                        editable: false
                    }, {
                        field: 'cardNo',
                        title: '身份证号',
                        visible :false,
                        editable: false,
                        cellStyle:{  
                            css:{"color":"#3276b1"}  //调整td字体颜色
                        } ,
                        formatter: function (value, row, index){ // 单元格格式化函数
                      		  var div = "<div style='width:100px;'>"+value+"</div>";//调列宽，在td中嵌套一个div，调整div大小
                          	  return div;
                        }
                    }, {
                        field: 'mobile',
                        title: '手机号',
                        visible :false,
                        editable: false
                    }, {
                        field: 'phone',
                        title: '座机号',
                        visible :false,
                        editable: false
                    }, {
                        field: 'father',
                        title: '父亲',
                        visible :false,
                        editable: false
                    }, {
                        field: 'monther',
                        title: '母亲',
                        visible :false,
                        editable: false
                    }, {
                        field: 'address',
                        title: '地址',
                        visible :false,
                        editable: false
                    }, {
                        field: 'extEvaluation',
                        title: '外部评估',
                        visible :false,
                        editable: false
                    }, {
                        field: 'evalName',
                        title: '内部评估',
                        editable: false ,
                        formatter: function (value,row,index) {
                        	 return (row.intEvaluation==null||row.intEvaluation=='undefined'||row.intEvaluation=='null')?"-":(row.intEvaluation+"-"+value);
                        }
                    }, {
                        field: 'operate',
                        title: '操作',
                        formatter: operateFormatter //自定义方法，添加操作按钮
                    }
                ],
                modalName: "孩子"
            };
            //1.初始化Table
            $.tableUtil.init(options);
            //2.初始化Button的点击事件
            $.buttonUtil.init(options);

            /**上传评估视频*/
            $('#versionlist').on('click', '.btn-uploadfile', function () {
                console.log("开始上传评估视频");
                var $this = $(this);
                var childId = $this.attr("data-id");
                $('#chooseFile').modal('show');
            });
            
            
            /**开始选择评估类型*/
            $('#tablelist').on('click', '.btn-evalcontext', function () {
                console.log("开始选择评估类型");
                var $this = $(this);
                var childId = $this.attr("data-id");
                
                $.ajax({
                    type: "post",
                    url: '/child/get/'+childId,
                    success: function (json) {
                        var info = json.data;
                        $('#intEvaluation').val(info.intEvaluation);
                        $('#whoschildid').val(childId);
                        $('#childTypeModalId').modal('show');
                        
                        
                    }
                });
                
               
                
            });
            
            $(".btn-eval").unbind('click');
            $(".btn-eval").click(function () {
                if (validator.checkAll($("#childEvalForm"))) {
                	//window.open('/child/evaluationContext/'+$('#whoschildid').val());
                	$.ajax({
                        type: "post",
                        url: '/child/saveChildType',
                        data: $("#childEvalForm").serialize(),
                        success: function (json) {
                        	window.location.href='/child/evaluationContext/'+$('#whoschildid').val();
                            $("#childTypeModalId").modal('hide');
                        }
                    }); 
                }else{
            		$.alert.ajaxSuccess({'success':200,'message':'孩子类型不能为空！'});
                	return false;
                }
            });
            
            
           
            
            
            /* 查看评估内容 */
            $('#tablelist').on('click', '.btn-vieweval', function () {
                console.log("查看评估内容");
                var $this = $(this);
                var childId = $this.attr("data-id");
                $('#versionlist').children().remove(); 
                
                function queryParams(params) {      
                	var temp = {   //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的         // limit: params.limit,   //页面大小         
                			offset: params.offset,  //页码          
                			pageSize:this.pageSize,          
                			pageNumber:this.pageNumber,         
                			"version.childId":childId,
                			length: 6      
                			};      
                	return temp;  
                };


                $('#versionlist').bootstrapTable('destroy').bootstrapTable({
                            url: '/child/versionAll/'+childId,
                            method: 'post',                      //请求方式（*）
                            striped: true,                      //是否显示行间隔色
                            cache: false,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
                            contentType: "application/x-www-form-urlencoded", // 发送到服务器的数据编码类型, application/x-www-form-urlencoded为了实现post方式提交
                            sortable: false,                     //是否启用排序
                            sortOrder: "asc",                   //排序方式
                            sortStable: true,                   // 设置为 true 将获得稳定的排序
                            queryParams: queryParams,//传递参数（*）
                            queryParamsType: '',
                            pagination: true,                   //是否显示分页（*）
                            sidePagination: "server",           //分页方式：client客户端分页，server服务端分页（*）
                            pageNumber: 1,                       //初始化加载第一页，默认第一页
                            pageSize: 10,                       //每页的记录行数（*）
                            pageList: [10,20, 40, 50, 100, 150],        //可供选择的每页的行数（*）
                            search: true,                       //是否启用搜索框 根据sidePagination选择从前后台搜索
                            strictSearch: true,                 //设置为 true启用 全匹配搜索，否则为模糊搜索
                            searchOnEnterKey: true,            // 设置为 true时，按回车触发搜索方法，否则自动触发搜索方法
                            minimumCountColumns: 1,             //最少允许的列数
                            showColumns: true,                  //是否显示 内容列下拉框
                            showRefresh: true,                  //是否显示刷新按钮
                            // detailView: true,                   //是否显示父子表
                            // showExport: true,                   //是否显示导出
                            // exportDataType: "basic",              //basic', 'all', 'selected'.
                            // clickToSelect: true,                //是否启用点击选中行
                            // singleSelect: true,
                            //height: 400,                        //行高，如果没有设置height属性，表格自动根据记录条数觉得表格高度
                            columns: [
                                  {
                                    field: 'id',
                                    title: '编号',
                                    visible :false,
                                    editable: false,
                                }/* , {
                                    field: 'intEvaluation',
                                    title: '孩子类型ID',
                                    visible :false,
                                    editable: false,
                                } */,  {
                                    field: 'evalName',
                                    title: '孩子类型',
                                    visible :true,
                                    editable: false,
                                    formatter: function (value,row,index) {
                                        return row.intEvaluation+"-"+value;
                                    }
                                }, {
                                    field: 'version',
                                    title: '版本',
                                    editable: false,
                                    formatter: function (value) {
                                        return "<a href='#'>"+value+"</a>";
                                    }
                                }, {
                                    field: 'evaldate',
                                    title: '评估日期',
                                    visible :true,
                                    editable: false,
                                    formatter: function (code) {
                                        return new Date(code).format("yyyy-MM-dd")
                                    }
                                }/* , {
                                    field: 'trainer',
                                    title: '负责训练者',
                                    visible :false,
                                    editable: false,
                                } */, {
                                    field: 'trainerName',
                                    title: '负责训练者',
                                    visible :true,
                                    editable: false,
                                }/* , {
                                    field: 'advocate',
                                    title: '咨询评估师',
                                    visible :false,
                                    editable: false,
                                } */, {
                                    field: 'advocateName',
                                    title: '咨询评估师',
                                    visible :true,
                                    editable: false,
                                }, {
                                    field: 'operate1',
                                    title: '操作',
                                    visible :true,
                                    events : operateEvents,
                                    formatter: operateVersion //自定义方法，添加操作按钮
                                }]
                        });
                        
                        $('#selectVersion').modal('show');
                      $("#versionlist").bootstrapTable('refresh', {url:'/child/versionAll/'+childId});
                });
            
            
            window.operateEvents = {
                    'click .btn-sendmail' : function(e, value, row, index) {
                    	var rowjson={"childId":row.childId,"version":row.version,"intEvaluation":row.intEvaluation,"trainer":row.trainer,"trainerName":row.trainerName,"advocate":row.advocate,"advocateName":row.advocateName,"evaldate":row.evaldate,"evalName":row.evalName};
                    	for(var i in row){
                    		console.log(i+":"+row[i]+",");
                    	} 
                    	$.ajax({
                             type: "post",
                             url: "/child/sendmail/" + JSON.stringify(rowjson),
                             success: function (json) {
                                 $.alert.ajaxSuccess(json);
                             },
                             error: $.alert.ajaxError
                         });
                    }
                }
            

            $('#versionlist').on('dbl-click-row.bs.table', function (e, row, element) 
        			{
        				//$(element).css({"color":"blue","font-size":"16px;"});
        				console.log(row);
        				getWriteDownDetail('/child/viewEvalContext',row);
        				//window.open('/child/viewEvalContext/'+JSON.stringify(row));
        				
        	});
        	
        	$('#versionlist').on('click-cell.bs.table', function (e, field, value, row, element) 
        			{
        				//$(element).css({"color":"blue","font-size":"16px;"});
        				if(field=="version"){
        					getWriteDownDetail('/child/viewEvalContext',row);
        				}
        				
        				
        	});
        	
        	
        	
            function getWriteDownDetail(url,row){
                //首先创建一个form表单  
                var tempForm = document.createElement("form");    
                tempForm.id="tempForm1";  
                //制定发送请求的方式为post  
                tempForm.method="post";   
                //此为window.open的url，通过表单的action来实现  
                tempForm.action=url;  
                //利用表单的target属性来绑定window.open的一些参数（如设置窗体属性的参数等）  
                tempForm.target="_blank";   
                //创建input标签，用来设置参数 
                
                for(v  in row){   
                	if(v=="createTime"||v=="updateTime")continue;
                	var hideInput = document.createElement("input");   
                	hideInput.type="hidden";    
                    hideInput.name= "version."+v;  
                    hideInput.value= row[v]; 
                    tempForm.appendChild(hideInput);
                }
          /*       var hideInput = document.createElement("input");    
                hideInput.type="hidden";    
                hideInput.name= "version.childId";  
                hideInput.value= row.childId; 
                var hideInput2 = document.createElement("input");  
                hideInput2.type = "hidden";  
                hideInput2.name = "version.version";
                hideInput2.value = row.version;
                var hideInput3 = document.createElement("input");  
                hideInput3.type = "hidden";  
                hideInput3.name = "version.trainer";
                hideInput3.value = row.trainer;
                var hideInput4 = document.createElement("input");  
                hideInput4.type = "hidden";  
                hideInput4.name = "version.advocate";
                hideInput4.value = row.advocate;
                var hideInput31 = document.createElement("input");  
                hideInput31.type = "hidden";  
                hideInput31.name = "version.trainerName";
                hideInput31.value = row.trainerName;
                var hideInput41 = document.createElement("input");  
                hideInput41.type = "hidden";  
                hideInput41.name = "version.advocateName";
                hideInput41.value = row.advocateName;
                var hideInput5 = document.createElement("input");  
                hideInput5.type = "hidden";  
                hideInput5.name = "version.evaldate";
                hideInput5.value = new Date(row.evaldate).format("yyyy-MM-dd");
                
                var hideInput6 = document.createElement("input");  
                hideInput6.type = "hidden";  
                hideInput6.name = "version.evalName";
                hideInput6.value = row.evalName;
                
                var hideInput7 = document.createElement("input");  
                hideInput7.type = "hidden";  
                hideInput7.name = "version.intEvaluation";
                hideInput7.value = row.intEvaluation;
                
                //将input表单放到form表单里  
                tempForm.appendChild(hideInput); 
                tempForm.appendChild(hideInput2);
                tempForm.appendChild(hideInput3);
                tempForm.appendChild(hideInput4);
                tempForm.appendChild(hideInput31);
                tempForm.appendChild(hideInput41);
                tempForm.appendChild(hideInput5);
                tempForm.appendChild(hideInput6);
                tempForm.appendChild(hideInput7); */
                //将此form表单添加到页面主体body中 
                document.body.appendChild(tempForm); 
                //手动触发，提交表单  
                tempForm.submit();
                //从body中移除form表单  
                document.body.removeChild(tempForm);  
            }
            
            /* 分配资源权限 */
            $('#tablelist').on('click', '.btn-evaluation', function () {
                console.log("开始评估");
                var $this = $(this);
                var rolesId = $this.attr("data-id");
                $.ajax({
                    async: false,
                    type: "POST",
                    data: {rid: '1'},
                    url: '/resources/resourcesWithSelected',
                    dataType: 'json',
                    success: function (json) {
                        var data = json.data;
                        console.log(data);
                        var setting = {
                            check: {
                                enable: true,
                                chkboxType: {"Y": "ps", "N": "ps"},
                                chkStyle: "checkbox"
                            },
                            data: {
                                simpleData: {
                                    enable: true
                                }
                            },
                            callback: {
                                onCheck: function (event, treeId, treeNode) {
                                    console.log(treeNode.tId + ", " + treeNode.name + "," + treeNode.checked);
                                    var treeObj = $.fn.zTree.getZTreeObj(treeId);
                                    var nodes = treeObj.getCheckedNodes(true);
                                    var ids = new Array();
                                    for (var i = 0; i < nodes.length; i++) {
                                        //获取选中节点的值
                                        ids.push(nodes[i].id);
                                    }
                                    console.log(ids);
                                    console.log(rolesId);
                                    $.post(options.saveRolesUrl, {"roleId": rolesId, "resourcesId": ids.join(",")}, function (obj) { }, 'json');
                                }
                            }
                        };
                        var tree = $.fn.zTree.init($("#treeEvaluation"), setting, data);
                        tree.expandAll(true);//全部展开

                        $('#selectEvaluationContent').modal('show');
                    }
                });
            });
            
        });